home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / tcl / tcl70b2.lha / tcl7.0b2 / tests / lsearch.test < prev    next >
Text File  |  1993-05-06  |  3KB  |  82 lines

  1. # Commands covered:  lsearch
  2. #
  3. # This file contains a collection of tests for one or more of the Tcl
  4. # built-in commands.  Sourcing this file into Tcl runs the tests and
  5. # generates output for errors.  No output means no errors were found.
  6. #
  7. # Copyright (c) 1991-1993 The Regents of the University of California.
  8. # All rights reserved.
  9. #
  10. # Permission is hereby granted, without written agreement and without
  11. # license or royalty fees, to use, copy, modify, and distribute this
  12. # software and its documentation for any purpose, provided that the
  13. # above copyright notice and the following two paragraphs appear in
  14. # all copies of this software.
  15. #
  16. # IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
  17. # DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
  18. # OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
  19. # CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  20. #
  21. # THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
  22. # INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
  23. # AND FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS
  24. # ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
  25. # PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
  26. #
  27. # $Header: /user6/ouster/tcl/tests/RCS/lsearch.test,v 1.3 93/05/06 16:18:04 ouster Exp $ (Berkeley)
  28.  
  29. if {[string compare test [info procs test]] == 1} then {source defs}
  30.  
  31. set x {abcd bbcd 123 234 345}
  32. test lsearch-1.1 {lsearch command} {
  33.     lsearch $x 123
  34. } 2
  35. test lsearch-1.2 {lsearch command} {
  36.     lsearch $x 3456
  37. } -1
  38. test lsearch-1.3 {lsearch command} {
  39.     lsearch $x *5
  40. } 4
  41. test lsearch-1.4 {lsearch command} {
  42.     lsearch $x *bc*
  43. } 0
  44.  
  45. test lsearch-2.1 {search modes} {
  46.     lsearch -exact {xyz bbcc *bc*} *bc*
  47. } 2
  48. test lsearch-2.2 {search modes} {
  49.     lsearch -exact {b.x ^bc xy bcx} ^bc
  50. } 1
  51. test lsearch-2.3 {search modes} {
  52.     list [catch {lsearch -regexp {xyz bbcc *bc*} *bc*} msg] $msg
  53. } {1 {couldn't compile regular expression pattern: ?+* follows nothing}}
  54. test lsearch-2.4 {search modes} {
  55.     lsearch -regexp {b.x ^bc xy bcx} ^bc
  56. } 3
  57. test lsearch-2.5 {search modes} {
  58.     lsearch -glob {xyz bbcc *bc*} *bc*
  59. } 1
  60. test lsearch-2.6 {search modes} {
  61.     lsearch -glob {b.x ^bc xy bcx} ^bc
  62. } 1
  63. test lsearch-2.7 {search modes} {
  64.     list [catch {lsearch -glib {b.x bx xy bcx} b.x} msg] $msg
  65. } {1 {bad search mode "-glib": must be -exact, -glob, or -regexp}}
  66.  
  67. test lsearch-3.1 {lsearch errors} {
  68.     list [catch lsearch msg] $msg
  69. } {1 {wrong # args: should be "lsearch ?mode? list pattern"}}
  70. test lsearch-3.2 {lsearch errors} {
  71.     list [catch {lsearch a} msg] $msg
  72. } {1 {wrong # args: should be "lsearch ?mode? list pattern"}}
  73. test lsearch-3.3 {lsearch errors} {
  74.     list [catch {lsearch a b c} msg] $msg
  75. } {1 {bad search mode "a": must be -exact, -glob, or -regexp}}
  76. test lsearch-3.4 {lsearch errors} {
  77.     list [catch {lsearch a b c d} msg] $msg
  78. } {1 {wrong # args: should be "lsearch ?mode? list pattern"}}
  79. test lsearch-3.5 {lsearch errors} {
  80.     list [catch {lsearch "\{" b} msg] $msg
  81. } {1 {unmatched open brace in list}}
  82.